<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qqmlcomponent.cpp -->
  <title>QQmlComponent  类 | Qt QML 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtqml-index.html">Qt QML</a></td><td ><a href="qtqml-module.html">C++ 类</a></td><td >QQmlComponent</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtqml-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#public-types">公用类型</a></li>
<li class="level1"><a href="#properties">属性</a></li>
<li class="level1"><a href="#public-functions">公用函数</a></li>
<li class="level1"><a href="#public-slots">公用槽函数</a></li>
<li class="level1"><a href="#signals">信号</a></li>
<li class="level1"><a href="#static-public-members">静态公用成员</a></li>
<li class="level1"><a href="#details">详细信息</a></li>
<li class="level2"><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#network-components">网络组件</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QQmlComponent 类</h1>
<!-- $$$QQmlComponent-brief -->
<p>
<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html">
QQmlComponent</a>类封装了QML组件定义。 <a href="#details">更多...</a></p>
<!-- @@@QQmlComponent -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> 头文件：</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QQmlComponent&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += qml</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign">  Qt 5.0</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Instantiated By:</td><td class="memItemRight bottomAlign"> <a href="qml-qtqml-component.html">Component</a></td></tr><tr><td class="memItemLeft rightAlign topAlign">继承自：</td><td class="memItemRight bottomAlign"> <a href="../qtcore/qobject.html">QObject</a></td></tr></table></div><ul>
<li><a href="qqmlcomponent-members.html"></a></li>
<li><a href="qqmlcomponent-obsolete.html">废弃的成员</a></li>
</ul>
<a name="public-types"></a>
<h2 id="public-types">公用类型</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#CompilationMode-enum">CompilationMode</a></b> { PreferSynchronous, Asynchronous }</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#Status-enum">Status</a></b> { Null, Ready, Loading, Error }</td></tr>
</table></div>
<a name="properties"></a>
<h2 id="properties">属性</h2>
<ul>
<li class="fn"><b><a href="qqmlcomponent.html#progress-prop">progress</a></b> : const qreal</li>
<li class="fn"><b><a href="qqmlcomponent.html#status-prop">status</a></b> : const Status</li>
<li class="fn"><b><a href="qqmlcomponent.html#url-prop">url</a></b> : const QUrl</li>
</ul>
<ul>
<li class="fn">1 个属性继承自<a href="../qtcore/qobject.html#properties">QObject</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">公用函数</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#QQmlComponent">QQmlComponent</a></b>(QQmlEngine *<i>engine</i>, QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#QQmlComponent-2">QQmlComponent</a></b>(QQmlEngine *<i>engine</i>, const QString &amp;<i>fileName</i>, QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#QQmlComponent-3">QQmlComponent</a></b>(QQmlEngine *<i>engine</i>, const QString &amp;<i>fileName</i>, QQmlComponent::CompilationMode <i>mode</i>, QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#QQmlComponent-4">QQmlComponent</a></b>(QQmlEngine *<i>engine</i>, const QUrl &amp;<i>url</i>, QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#QQmlComponent-5">QQmlComponent</a></b>(QQmlEngine *<i>engine</i>, const QUrl &amp;<i>url</i>, QQmlComponent::CompilationMode <i>mode</i>, QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#dtor.QQmlComponent">~QQmlComponent</a></b>() override</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QObject *</td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#beginCreate">beginCreate</a></b>(QQmlContext *<i>publicContext</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#completeCreate">completeCreate</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QObject *</td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#create">create</a></b>(QQmlContext *<i>context</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#create-1">create</a></b>(QQmlIncubator &amp;<i>incubator</i>, QQmlContext *<i>context</i> = nullptr, QQmlContext *<i>forContext</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QQmlContext *</td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#creationContext">creationContext</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QQmlEngine *</td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#engine">engine</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QList&lt;QQmlError&gt; </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#errors">errors</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#isError">isError</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#isLoading">isLoading</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#isNull">isNull</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#isReady">isReady</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qreal </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#progress-prop">progress</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QQmlComponent::Status </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#status-prop">status</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QUrl </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#url-prop">url</a></b>() const</td></tr>
</table></div>
<ul>
<li class="fn">31 个公用函数继承自<a href="../qtcore/qobject.html#public-functions">QObject</a></li>
</ul>
<a name="public-slots"></a>
<h2 id="public-slots">公用槽函数</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#loadUrl">loadUrl</a></b>(const QUrl &amp;<i>url</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#loadUrl-1">loadUrl</a></b>(const QUrl &amp;<i>url</i>, QQmlComponent::CompilationMode <i>mode</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#setData">setData</a></b>(const QByteArray &amp;<i>data</i>, const QUrl &amp;<i>url</i>)</td></tr>
</table></div>
<ul>
<li class="fn">1 个公用槽函数继承自<a href="../qtcore/qobject.html#public-slots">QObject</a></li>
</ul>
<a name="signals"></a>
<h2 id="signals">信号</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#progressChanged">progressChanged</a></b>(qreal <i>progress</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#statusChanged">statusChanged</a></b>(QQmlComponent::Status <i>status</i>)</td></tr>
</table></div>
<ul>
<li class="fn">2 个信号继承自<a href="../qtcore/qobject.html#signals">QObject</a></li>
</ul>
<a name="static-public-members"></a>
<h2 id="static-public-members">静态公用成员</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> const QMetaObject </td><td class="memItemRight bottomAlign"><b><a href="qqmlcomponent.html#staticMetaObject-var">staticMetaObject</a></b></td></tr>
</table></div>
<ul>
<li class="fn">9 个静态公用成员继承自<a href="../qtcore/qobject.html#static-public-members">QObject</a></li>
</ul>
<h3>额外的继承成员</h3>
<ul>
<li class="fn">9 个保护函数继承自<a href="../qtcore/qobject.html#protected-functions">QObject</a></li>
</ul>
<a name="details"></a>
<!-- $$$QQmlComponent-description -->
<div class="descr">
<h2 id="details">详细信息</h2>
<p><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html">QQmlComponent</a>类封装了QML组件定义。</p>
<p>组件是可重用、封装的 QML 类型，具有明确定义的接口。</p>
<p>一个<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html">QQmlComponent</a>实例可以从QML文件被创建。例如，如果有这样一个<code>main.qml</code>文件：</p>
<pre class="qml">

  import QtQuick 2.0

  <span class="type"><a href="../qtquick/qml-qtquick-item.html">Item</a></span> {
      <span class="name">width</span>: <span class="number">200</span>
      <span class="name">height</span>: <span class="number">200</span>
  }

</pre>
<p>以下代码将这个 QML 文件作为组件加载，使用<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#create">create</a> ()<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#create">创建</a>这个组件的实例，然后查询<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtquick/qml-qtquick-item.html">Item</a>的<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtquick/qml-qtquick-item.html#width-prop">宽度</a>值：</p>
<pre class="cpp">

  <span class="type"><a href="qqmlengine.html">QQmlEngine</a></span> <span class="operator">*</span>engine <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qqmlengine.html">QQmlEngine</a></span>;
  <span class="type"><a href="qqmlcomponent.html#QQmlComponent">QQmlComponent</a></span> component(engine<span class="operator">,</span> <span class="type"><a href="../qtcore/qurl.html">QUrl</a></span><span class="operator">::</span>fromLocalFile(<span class="string">&quot;main.qml&quot;</span>));

  <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> <span class="operator">*</span>myObject <span class="operator">=</span> component<span class="operator">.</span>create();
  <span class="type"><a href="../qtquick/qquickitem.html">QQuickItem</a></span> <span class="operator">*</span>item <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span><span class="type"><a href="../qtquick/qquickitem.html">QQuickItem</a></span><span class="operator">*</span><span class="operator">&gt;</span>(myObject);
  <span class="type">int</span> width <span class="operator">=</span> item<span class="operator">-</span><span class="operator">&gt;</span>width();  <span class="comment">// width = 200</span>

</pre>
<p>要在代码中创建<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlengine.html">QQmlEngine</a>实例不可用的组件实例，可以使用<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlengine.html#qmlContext">qmlContext</a> () 或<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlengine.html#qmlEngine">qmlEngine</a> ()。例如，在下面的场景中，正在<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtquick/qquickitem.html">QQuickItem</a>子类中创建子项：</p>
<pre class="cpp">

  <span class="type">void</span> MyCppItem<span class="operator">::</span>init()
  {
      <span class="type"><a href="qqmlengine.html">QQmlEngine</a></span> <span class="operator">*</span>engine <span class="operator">=</span> qmlEngine(<span class="keyword">this</span>);
      <span class="comment">// Or:</span>
      <span class="comment">// QQmlEngine *engine = qmlContext(this)-&gt;engine();</span>
      <span class="type"><a href="qqmlcomponent.html#QQmlComponent">QQmlComponent</a></span> component(engine<span class="operator">,</span> <span class="type"><a href="../qtcore/qurl.html">QUrl</a></span><span class="operator">::</span>fromLocalFile(<span class="string">&quot;MyItem.qml&quot;</span>));
      <span class="type"><a href="../qtquick/qquickitem.html">QQuickItem</a></span> <span class="operator">*</span>childItem <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span><span class="type"><a href="../qtquick/qquickitem.html">QQuickItem</a></span><span class="operator">*</span><span class="operator">&gt;</span>(component<span class="operator">.</span>create());
      childItem<span class="operator">-</span><span class="operator">&gt;</span>setParentItem(<span class="keyword">this</span>);
  }

</pre>
<p>请注意，<code>null</code>当在<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtcore/qobject.html">QObject</a>子类的构造函数中调用时，这些函数将返回，因为实例还没有上下文或引擎。</p>
<a name="network-components"></a>
<h4 >网络组件</h4>
<p>如果传递给<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html">QQmlComponent</a>的 URL是网络资源，或者 QML 文档引用了网络资源，则<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html">QQmlComponent</a>必须先获取网络数据，然后才能创建对象。在这种情况下，<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html">QQmlComponent</a>将具有<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#Status-enum">Loading</a> <a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#status-prop">状态</a>。在调用<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#create">QQmlComponent::create</a> ()之前，应用程序必须等待组件<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#Status-enum"><span lang="zh-cn">Ready（就绪）</span></a>。</p>
<p>以下示例显示如何从网络资源加载 QML 文件。创建<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html">QQmlComponent 后</a>，它会测试该组件是否正在加载。如果是，则连接到<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#statusChanged">QQmlComponent::statusChanged</a> () 信号，否则<code>continueLoading()</code>直接调用该方法。请注意，如果组件已被缓存并立即准备就绪，则网络组件的<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#isLoading">QQmlComponent::isLoading</a> () 可能为 false。</p>
<pre class="cpp">

  MyApplication<span class="operator">::</span>MyApplication()
  {
      <span class="comment">// ...</span>
      component <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qqmlcomponent.html#QQmlComponent">QQmlComponent</a></span>(engine<span class="operator">,</span> <span class="type"><a href="../qtcore/qurl.html">QUrl</a></span>(<span class="string">&quot;http://www.example.com/main.qml&quot;</span>));
      <span class="keyword">if</span> (component<span class="operator">-</span><span class="operator">&gt;</span>isLoading())
          <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span><span class="operator">::</span>connect(component<span class="operator">,</span> SIGNAL(statusChanged(<span class="type"><a href="qqmlcomponent.html#QQmlComponent">QQmlComponent</a></span><span class="operator">::</span>Status))<span class="operator">,</span>
                           <span class="keyword">this</span><span class="operator">,</span> SLOT(continueLoading()));
      <span class="keyword">else</span>
          continueLoading();
  }

  <span class="type">void</span> MyApplication<span class="operator">::</span>continueLoading()
  {
      <span class="keyword">if</span> (component<span class="operator">-</span><span class="operator">&gt;</span>isError()) {
          <a href="../qtcore/qtglobal.html#qWarning">qWarning</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> component<span class="operator">-</span><span class="operator">&gt;</span>errors();
      } <span class="keyword">else</span> {
          <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> <span class="operator">*</span>myObject <span class="operator">=</span> component<span class="operator">-</span><span class="operator">&gt;</span>create();
      }
  }

</pre>
</div>
<!-- @@@QQmlComponent -->
<div class="types">
<h2>成员类型文档</h2>
<!-- $$$CompilationMode$$$PreferSynchronous$$$Asynchronous -->
<h3 class="fn" id="CompilationMode-enum"><a name="CompilationMode-enum"></a>enum QQmlComponent::<span class="name">CompilationMode</span></h3>
<p>指定<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html">QQmlComponent</a>应立即加载组件还是异步加载组件。</p>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">
	<span lang="zh-cn">常量</span></th><th class="tblval"><span lang="zh-cn">值</span></th><th class="tbldscr">
	<span lang="zh-cn">描述</span></th></tr>
<tr><td class="topAlign"><code>QQmlComponent::PreferSynchronous</code></td><td class="topAlign tblval"><code>0</code></td><td class="topAlign">
	更喜欢立即加载/编译组件，阻塞线程。这并不总是可能的；例如，远程 URL 将始终异步加载。</td></tr>
<tr><td class="topAlign"><code>QQmlComponent::Asynchronous</code></td><td class="topAlign tblval"><code>1</code></td><td class="topAlign">
	在后台线程中加载/编译组件。</td></tr>
</table></div>
<!-- @@@CompilationMode -->
<!-- $$$Status$$$Null$$$Ready$$$Loading$$$Error -->
<h3 class="fn" id="Status-enum"><a name="Status-enum"></a>enum QQmlComponent::<span class="name">Status</span></h3>
<p>指定<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html">QQmlComponent</a>的加载状态。</p>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">
	<span lang="zh-cn">常量</span></th><th class="tblval"><span lang="zh-cn">值</span></th><th class="tbldscr">
	<span lang="zh-cn">描述</span></th></tr>
<tr><td class="topAlign"><code>QQmlComponent::Null</code></td><td class="topAlign tblval"><code>0</code></td><td class="topAlign">这个<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html">QQmlComponent</a>没有数据。调用<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#loadUrl">loadUrl</a> () 或<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#setData">setData</a> () 添加 QML 内容。</td></tr>
<tr><td class="topAlign"><code>QQmlComponent::Ready</code></td><td class="topAlign tblval"><code>1</code></td><td class="topAlign">这个<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html">QQmlComponent</a>已经准备好了，可以调用<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#create">create</a> ()了。</td></tr>
<tr><td class="topAlign"><code>QQmlComponent::Loading</code></td><td class="topAlign tblval"><code>2</code></td><td class="topAlign">这个<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html">QQmlComponent</a>正在加载网络数据。</td></tr>
<tr><td class="topAlign"><code>QQmlComponent::Error</code></td><td class="topAlign tblval"><code>3</code></td><td class="topAlign">发生了错误。调用<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#errors">errors</a> () 来检索<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlerror.html">错误</a>列表。</td></tr>
</table></div>
<!-- @@@Status -->
</div>
<div class="prop">
<h2>属性的文档</h2>
<!-- $$$progress-prop$$$progress$$$progressChangedqreal -->
<h3 class="fn" id="progress-prop"><a name="progress-prop"></a><span class="name">progress</span> : const <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span></h3>
<p><font style="vertical-align: inherit;">加载组件的进度，从 0.0（没有加载）到 1.0（完成）。</font></p>
<p><b>访问函数：</b></p>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft topAlign rightAlign"> qreal </td><td class="memItemRight bottomAlign"><span class="name"><b>progress</b></span>() const</td></tr>
</table></div>
<p><b><font style="vertical-align: inherit;">通知信号：</font></b></p>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft topAlign rightAlign"> void </td><td class="memItemRight bottomAlign"><span class="name"><b><a href="qqmlcomponent.html#progressChanged">progressChanged</a></b></span>(qreal <i>progress</i>)</td></tr>
</table></div>
<!-- @@@progress -->
<!-- $$$status-prop$$$status$$$statusChangedQQmlComponent::Status -->
<h3 class="fn" id="status-prop"><a name="status-prop"></a><span class="name">status</span> : const <span class="type"><a href="qqmlcomponent.html#Status-enum">Status</a></span></h3>
<p><font style="vertical-align: inherit;">组件的当前</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#Status-enum"><font style="vertical-align: inherit;">状态</font></a><font style="vertical-align: inherit;">。</font></p>
<p><b>访问函数：</b></p>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft topAlign rightAlign"> QQmlComponent::Status </td><td class="memItemRight bottomAlign"><span class="name"><b>status</b></span>() const</td></tr>
</table></div>
<p><b><font style="vertical-align: inherit;">通知信号：</font></b></p>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft topAlign rightAlign"> void </td><td class="memItemRight bottomAlign"><span class="name"><b><a href="qqmlcomponent.html#statusChanged">statusChanged</a></b></span>(QQmlComponent::Status <i>status</i>)</td></tr>
</table></div>
<!-- @@@status -->
<!-- $$$url-prop$$$url -->
<h3 class="fn" id="url-prop"><a name="url-prop"></a><span class="name">url</span> : const <span class="type"><a href="../qtcore/qurl.html">QUrl</a></span></h3>
<p><font style="vertical-align: inherit;">组件 URL。这是传递给构造函数或</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#loadUrl"><font style="vertical-align: inherit;">loadUrl</font></a><font style="vertical-align: inherit;"> () 或</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#setData"><font style="vertical-align: inherit;">setData</font></a><font style="vertical-align: inherit;"> () 方法的 URL 。</font></p>
<p><b>访问函数：</b></p>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft topAlign rightAlign"> QUrl </td><td class="memItemRight bottomAlign"><span class="name"><b>url</b></span>() const</td></tr>
</table></div>
<!-- @@@url -->
</div>
<div class="func">
<h2>成员函数文档</h2>
<!-- $$$QQmlComponent[overload1]$$$QQmlComponentQQmlEngine*QObject* -->
<h3 class="fn" id="QQmlComponent"><a name="QQmlComponent"></a>QQmlComponent::<span class="name">QQmlComponent</span>(<span class="type"><a href="qqmlengine.html">QQmlEngine</a></span> *<i>engine</i>, <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<p><font style="vertical-align: inherit;">创建一个没有数据的</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html"><font style="vertical-align: inherit;">QQmlComponent</font></a><font style="vertical-align: inherit;">并给它指定的</font><i><font style="vertical-align: inherit;">engine</font></i><font style="vertical-align: inherit;">和</font><i><font style="vertical-align: inherit;">parent</font></i><font style="vertical-align: inherit;">。用</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#setData"><font style="vertical-align: inherit;">setData</font></a><font style="vertical-align: inherit;"> ()设置数据。</font></p>
<!-- @@@QQmlComponent -->
<!-- $$$QQmlComponent$$$QQmlComponentQQmlEngine*constQString&QObject* -->
<h3 class="fn" id="QQmlComponent-2"><a name="QQmlComponent-2"></a>QQmlComponent::<span class="name">QQmlComponent</span>(<span class="type"><a href="qqmlengine.html">QQmlEngine</a></span> *<i>engine</i>, const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>fileName</i>, <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<p><font style="vertical-align: inherit;">从给定的<i>fileName</i>创建一个</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html"><font style="vertical-align: inherit;">QQmlComponent</font></a><font style="vertical-align: inherit;">并为其提供指定的<i>parent</i>和<i>engine</i>。</font></p>
<p><b>请参考 </b><a href="qqmlcomponent.html#loadUrl">loadUrl</a>()<span lang="zh-cn">。</span></p>
<!-- @@@QQmlComponent -->
<!-- $$$QQmlComponent$$$QQmlComponentQQmlEngine*constQString&QQmlComponent::CompilationModeQObject* -->
<h3 class="fn" id="QQmlComponent-3"><a name="QQmlComponent-3"></a>QQmlComponent::<span class="name">QQmlComponent</span>(<span class="type"><a href="qqmlengine.html">QQmlEngine</a></span> *<i>engine</i>, const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>fileName</i>, <span class="type"><a href="qqmlcomponent.html#CompilationMode-enum">QQmlComponent::CompilationMode</a></span> <i>mode</i>, <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<p><font style="vertical-align: inherit;">从给定的<i>fileName</i>创建一个</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html"><font style="vertical-align: inherit;">QQmlComponent</font></a><font style="vertical-align: inherit;">并为其提供指定的<i>parent</i>和<i>engine</i>。如果<i>mode</i>为<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#CompilationMode-enum">Asynchronous</a>，则组件将异步加载和编译。</font></p>
<p><b>请参考 </b><a href="qqmlcomponent.html#loadUrl">loadUrl</a>()<span lang="zh-cn">。</span></p>
<!-- @@@QQmlComponent -->
<!-- $$$QQmlComponent$$$QQmlComponentQQmlEngine*constQUrl&QObject* -->
<h3 class="fn" id="QQmlComponent-4"><a name="QQmlComponent-4"></a>QQmlComponent::<span class="name">QQmlComponent</span>(<span class="type"><a href="qqmlengine.html">QQmlEngine</a></span> *<i>engine</i>, const <span class="type"><a href="../qtcore/qurl.html">QUrl</a></span> &amp;<i>url</i>, <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<p><font style="vertical-align: inherit;">从给定的<i>url</i>创建一个</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html"><font style="vertical-align: inherit;">QQmlComponent</font></a><font style="vertical-align: inherit;">并给它指定的<i>parent</i>和<i>engine</i>。</font></p>
<p><font style="vertical-align: inherit;">确保提供的 URL 完整且正确，特别是从本地文件系统加载文件时使用</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtcore/qurl.html#fromLocalFile"><font style="vertical-align: inherit;">QUrl::fromLocalFile</font></a><font style="vertical-align: inherit;"> ()。</font></p>
<p><font style="vertical-align: inherit;">相对路径将针对</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlengine.html#baseUrl"><font style="vertical-align: inherit;">QQmlEngine::baseUrl()</font></a><font style="vertical-align: inherit;">解析，除非指定，否则它是当前工作目录。</font></p>
<p><b><font style="vertical-align: inherit;">请参考</font></b><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#loadUrl"><font style="vertical-align: inherit;">loadUrl</font></a><font style="vertical-align: inherit;"> ()。</font></p>
<!-- @@@QQmlComponent -->
<!-- $$$QQmlComponent$$$QQmlComponentQQmlEngine*constQUrl&QQmlComponent::CompilationModeQObject* -->
<h3 class="fn" id="QQmlComponent-5"><a name="QQmlComponent-5"></a>QQmlComponent::<span class="name">QQmlComponent</span>(<span class="type"><a href="qqmlengine.html">QQmlEngine</a></span> *<i>engine</i>, const <span class="type"><a href="../qtcore/qurl.html">QUrl</a></span> &amp;<i>url</i>, <span class="type"><a href="qqmlcomponent.html#CompilationMode-enum">QQmlComponent::CompilationMode</a></span> <i>mode</i>, <span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<p><font style="vertical-align: inherit;">从给定的<i>url</i>创建一个</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html"><font style="vertical-align: inherit;">QQmlComponent</font></a><font style="vertical-align: inherit;">并给它指定的<i>parent</i>和<i>engine</i>。如果<i>mode</i>为<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#CompilationMode-enum">Asynchronous</a>，则组件将异步加载和编译。</font></p>
<p><font style="vertical-align: inherit;">确保提供的 URL 完整且正确，特别是从本地文件系统加载文件时使用</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtcore/qurl.html#fromLocalFile"><font style="vertical-align: inherit;">QUrl::fromLocalFile</font></a><font style="vertical-align: inherit;"> ()。</font></p>
<p><font style="vertical-align: inherit;">相对路径将针对</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlengine.html#baseUrl"><font style="vertical-align: inherit;">QQmlEngine::baseUrl()</font></a><font style="vertical-align: inherit;">解析，除非指定，否则它是当前工作目录。</font></p>
<p><b>请参考 </b><a href="qqmlcomponent.html#loadUrl">loadUrl</a>()<span lang="zh-cn">。</span></p>
<!-- @@@QQmlComponent -->
<!-- $$$~QQmlComponent[overload1]$$$~QQmlComponent -->
<h3 class="fn" id="dtor.QQmlComponent"><a name="dtor.QQmlComponent"></a><code>[override virtual] </code>QQmlComponent::<span class="name">~QQmlComponent</span>()</h3>
<p><font style="vertical-align: inherit;">销毁</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html"><font style="vertical-align: inherit;">QQmlComponent</font></a><font style="vertical-align: inherit;">。</font></p>
<!-- @@@~QQmlComponent -->
<!-- $$$beginCreate[overload1]$$$beginCreateQQmlContext* -->
<h3 class="fn" id="beginCreate"><a name="beginCreate"></a><code>[virtual] </code><span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *QQmlComponent::<span class="name">beginCreate</span>(<span class="type"><a href="qqmlcontext.html">QQmlContext</a></span> *<i>publicContext</i>)</h3>
<p><font style="vertical-align: inherit;">此方法提供对组件实例创建的高级控制。一般来说，程序员应该使用</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#create"><font style="vertical-align: inherit;">QQmlComponent::create</font></a><font style="vertical-align: inherit;"> ()来创建对象实例。</font></p>
<p><font style="vertical-align: inherit;">从该组件创建一个对象实例。</font><code>nullptr</code><font style="vertical-align: inherit;">如果创建失败则返回。</font><i><font style="vertical-align: inherit;">publicContext</font></i><font style="vertical-align: inherit;">指定在其中创建对象实例的上下文。</font></p>
<p><font style="vertical-align: inherit;">当</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html"><font style="vertical-align: inherit;">QQmlComponent</font></a><font style="vertical-align: inherit;">构建一个实例，它发生在三个步骤：</font></p>
<ol class="1" type="1"><li><font style="vertical-align: inherit;">创建对象层次结构，并分配常量值。</font></li>
<li><font style="vertical-align: inherit;">首次评估属性绑定。</font></li>
<li><font style="vertical-align: inherit;">如果适用，在对象上调用</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlparserstatus.html#componentComplete"><font style="vertical-align: inherit;">QQmlParserStatus::componentComplete</font></a><font style="vertical-align: inherit;"> ()。</font></li>
</ol>
<p><font style="vertical-align: inherit;">QQmlComponent::beginCreate() 与</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#create"><font style="vertical-align: inherit;">QQmlComponent::create</font></a><font style="vertical-align: inherit;"> () 的不同之处在于它只执行第 1</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#completeCreate"><font style="vertical-align: inherit;">步，</font></a><font style="vertical-align: inherit;">必须调用<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#completeCreate">QQmlComponent::completeCreate</a> () 才能完成第 2 步和第 3 步。</font></p>
<p><font style="vertical-align: inherit;">当使用附加属性将信息传递给实例化组件时，此断点有时很有用，因为它允许在属性绑定生效之前配置它们的初始值。</font></p>
<p><font style="vertical-align: inherit;">返回的对象实例的所有权转移给调用者。</font></p>
<p><b>请参考 </b><a href="qqmlcomponent.html#completeCreate">completeCreate</a>()
<span lang="zh-cn">和 </span><a href="qqmlengine.html#ObjectOwnership-enum">QQmlEngine::ObjectOwnership</a><span lang="zh-cn">。</span></p>
<!-- @@@beginCreate -->
<!-- $$$completeCreate[overload1]$$$completeCreate -->
<h3 class="fn" id="completeCreate"><a name="completeCreate"></a><code>[virtual] </code><span class="type">void</span> QQmlComponent::<span class="name">completeCreate</span>()</h3>
<p><font style="vertical-align: inherit;">此方法提供对组件实例创建的高级控制。一般来说，程序员应该使用</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#create"><font style="vertical-align: inherit;">QQmlComponent::create</font></a><font style="vertical-align: inherit;"> ()来创建组件。</font></p>
<p><font style="vertical-align: inherit;">该函数完成了从</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#beginCreate"><font style="vertical-align: inherit;">QQmlComponent::beginCreate</font></a><font style="vertical-align: inherit;"> ()开始的组件创建，之后必须调用。</font></p>
<p><b>请参考 </b><a href="qqmlcomponent.html#beginCreate">beginCreate</a>()<span lang="zh-cn">。</span></p>
<!-- @@@completeCreate -->
<!-- $$$create[overload1]$$$createQQmlContext* -->
<h3 class="fn" id="create"><a name="create"></a><code>[virtual] </code><span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *QQmlComponent::<span class="name">create</span>(<span class="type"><a href="qqmlcontext.html">QQmlContext</a></span> *<i>context</i> = nullptr)</h3>
<p><font style="vertical-align: inherit;">从该组件创建一个对象实例。</font><code>nullptr</code><font style="vertical-align: inherit;">如果创建失败则返回。<i>context</i> 指定在其中创建对象实例的上下文。</font></p>
<p><font style="vertical-align: inherit;">如果<i>context</i> 是</font><code>nullptr</code><font style="vertical-align: inherit;">（默认值），它将在引擎的</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlengine.html#rootContext"><font style="vertical-align: inherit;">根上下文</font></a><font style="vertical-align: inherit;">中创建实例。</font></p>
<p><font style="vertical-align: inherit;">返回的对象实例的所有权转移给调用者。</font></p>
<p><font style="vertical-align: inherit;">如果从这个组件创建的对象是一个可视项，它必须有一个可视父项，可以通过调用</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtquick/qquickitem.html#parent-prop"><font style="vertical-align: inherit;">QQuickItem::setParentItem</font></a><font style="vertical-align: inherit;"> ()来设置。有关更多详细信息，请参阅</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtquick/qtquick-visualcanvas-visualparent.html"><font style="vertical-align: inherit;">概念 - Qt Quick 中的可视化父级</font></a><font style="vertical-align: inherit;">。</font></p>
<p><b>请参考 </b><a href="qqmlengine.html#ObjectOwnership-enum">QQmlEngine::ObjectOwnership</a><span lang="zh-cn">。</span></p>
<!-- @@@create -->
<!-- $$$create$$$createQQmlIncubator&QQmlContext*QQmlContext* -->
<h3 class="fn" id="create-1"><a name="create-1"></a><span class="type">void</span> QQmlComponent::<span class="name">create</span>(<span class="type"><a href="qqmlincubator.html">QQmlIncubator</a></span> &amp;<i>incubator</i>, <span class="type"><a href="qqmlcontext.html">QQmlContext</a></span> *<i>context</i> = nullptr, <span class="type"><a href="qqmlcontext.html">QQmlContext</a></span> *<i>forContext</i> = nullptr)</h3>
<p><font style="vertical-align: inherit;">使用提供的<i>incubator</i>从此组件创建对象实例。<i>context</i> 指定在其中创建对象实例的上下文。</font></p>
<p><font style="vertical-align: inherit;">如果<i>context</i> 为 0（默认值），它将在引擎的</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlengine.html#rootContext"><font style="vertical-align: inherit;">根上下文中</font></a><font style="vertical-align: inherit;">创建实例。</font></p>
<p><i><font style="vertical-align: inherit;">forContext</font></i><font style="vertical-align: inherit;">指定此对象创建所依赖的上下文。如果</font><i><font style="vertical-align: inherit;">forContext</font></i><font style="vertical-align: inherit;">是异步创建的，并且</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlincubator.html#IncubationMode-enum"><font style="vertical-align: inherit;">QQmlIncubator::IncubationMode</font></a><font style="vertical-align: inherit;">是</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlincubator.html#IncubationMode-enum"><font style="vertical-align: inherit;">QQmlIncubator::AsynchronousIfNested</font></a><font style="vertical-align: inherit;">，则该对象也将异步创建。如果</font><i><font style="vertical-align: inherit;">forContext</font></i><font style="vertical-align: inherit;">为 0（默认值），则<i>context</i> 将用于此决策。</font></p>
<p><font style="vertical-align: inherit;">创建的对象及其创建状态可通过</font><i><font style="vertical-align: inherit;">incubator 获得</font></i><font style="vertical-align: inherit;">。</font></p>
<p><b>请参考 </b><a href="qqmlincubator.html">QQmlIncubator</a><span lang="zh-cn">。</span></p>
<!-- @@@create -->
<!-- $$$creationContext[overload1]$$$creationContext -->
<h3 class="fn" id="creationContext"><a name="creationContext"></a><span class="type"><a href="qqmlcontext.html">QQmlContext</a></span> *QQmlComponent::<span class="name">creationContext</span>() const</h3>
<p><font style="vertical-align: inherit;">返回组件在其中创建的</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcontext.html"><font style="vertical-align: inherit;">QQmlContext</font></a><font style="vertical-align: inherit;">。这仅对直接从 QML 创建的组件有效。</font></p>
<!-- @@@creationContext -->
<!-- $$$engine[overload1]$$$engine -->
<h3 class="fn" id="engine"><a name="engine"></a><span class="type"><a href="qqmlengine.html">QQmlEngine</a></span> *QQmlComponent::<span class="name">engine</span>() const</h3>
<p><font style="vertical-align: inherit;">返回此组件的</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlengine.html"><font style="vertical-align: inherit;">QQmlEngine</font></a><font style="vertical-align: inherit;">。</font></p>
<p>这个函数在Qt 5.12中引入。</p>
<!-- @@@engine -->
<!-- $$$errors[overload1]$$$errors -->
<h3 class="fn" id="errors"><a name="errors"></a><span class="type"><a href="../qtcore/qlist.html">QList</a></span>&lt;<span class="type"><a href="qqmlerror.html">QQmlError</a></span>&gt; QQmlComponent::<span class="name">errors</span>() const</h3>
<p><font style="vertical-align: inherit;">返回上次编译或创建操作期间发生的错误列表。如果未设置</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#isError"><font style="vertical-align: inherit;">isError</font></a><font style="vertical-align: inherit;"> ()，则返回一个空列表。</font></p>
<!-- @@@errors -->
<!-- $$$isError[overload1]$$$isError -->
<h3 class="fn" id="isError"><a name="isError"></a><span class="type">bool</span> QQmlComponent::<span class="name">isError</span>() const</h3>
<p><font style="vertical-align: inherit;">如果</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#status-prop"><font style="vertical-align: inherit;">status</font></a><font style="vertical-align: inherit;"> () == </font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#Status-enum"><font style="vertical-align: inherit;">QQmlComponent::Error</font></a><font style="vertical-align: inherit;">则返回 true 。</font></p>
<!-- @@@isError -->
<!-- $$$isLoading[overload1]$$$isLoading -->
<h3 class="fn" id="isLoading"><a name="isLoading"></a><span class="type">bool</span> QQmlComponent::<span class="name">isLoading</span>() const</h3>
<p><font style="vertical-align: inherit;">如果</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#status-prop"><font style="vertical-align: inherit;">status</font></a><font style="vertical-align: inherit;"> () == </font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#Status-enum"><font style="vertical-align: inherit;">QQmlComponent::Loading</font></a><font style="vertical-align: inherit;">则返回 true 。</font></p>
<!-- @@@isLoading -->
<!-- $$$isNull[overload1]$$$isNull -->
<h3 class="fn" id="isNull"><a name="isNull"></a><span class="type">bool</span> QQmlComponent::<span class="name">isNull</span>() const</h3>
<p><font style="vertical-align: inherit;">如果</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#status-prop"><font style="vertical-align: inherit;">status</font></a><font style="vertical-align: inherit;"> () == </font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#Status-enum"><font style="vertical-align: inherit;">QQmlComponent::Null ，</font></a><font style="vertical-align: inherit;">则返回 true 。</font></p>
<!-- @@@isNull -->
<!-- $$$isReady[overload1]$$$isReady -->
<h3 class="fn" id="isReady"><a name="isReady"></a><span class="type">bool</span> QQmlComponent::<span class="name">isReady</span>() const</h3>
<p><font style="vertical-align: inherit;">如果</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#status-prop"><font style="vertical-align: inherit;">status</font></a><font style="vertical-align: inherit;"> () == </font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#Status-enum"><font style="vertical-align: inherit;">QQmlComponent::Ready</font></a><font style="vertical-align: inherit;">则返回 true 。</font></p>
<!-- @@@isReady -->
<!-- $$$loadUrl[overload1]$$$loadUrlconstQUrl& -->
<h3 class="fn" id="loadUrl"><a name="loadUrl"></a><code>[slot] </code><span class="type">void</span> QQmlComponent::<span class="name">loadUrl</span>(const <span class="type"><a href="../qtcore/qurl.html">QUrl</a></span> &amp;<i>url</i>)</h3>
<p><font style="vertical-align: inherit;">从提供的<i>url</i>加载</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html"><font style="vertical-align: inherit;">QQmlComponent</font></a><font style="vertical-align: inherit;">。</font></p>
<p><font style="vertical-align: inherit;">确保提供的 URL 完整且正确，特别是从本地文件系统加载文件时使用</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtcore/qurl.html#fromLocalFile"><font style="vertical-align: inherit;">QUrl::fromLocalFile</font></a><font style="vertical-align: inherit;"> ()。</font></p>
<p><font style="vertical-align: inherit;">相对路径将针对</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlengine.html#baseUrl"><font style="vertical-align: inherit;">QQmlEngine::baseUrl()</font></a><font style="vertical-align: inherit;">解析，除非指定，否则它是当前工作目录。</font></p>
<!-- @@@loadUrl -->
<!-- $$$loadUrl$$$loadUrlconstQUrl&QQmlComponent::CompilationMode -->
<h3 class="fn" id="loadUrl-1"><a name="loadUrl-1"></a><code>[slot] </code><span class="type">void</span> QQmlComponent::<span class="name">loadUrl</span>(const <span class="type"><a href="../qtcore/qurl.html">QUrl</a></span> &amp;<i>url</i>, <span class="type"><a href="qqmlcomponent.html#CompilationMode-enum">QQmlComponent::CompilationMode</a></span> <i>mode</i>)</h3>
<p><font style="vertical-align: inherit;">从提供的<i>url</i>加载</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html"><font style="vertical-align: inherit;">QQmlComponent</font></a><font style="vertical-align: inherit;">。如果<i>mode</i>为<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#CompilationMode-enum">Asynchronous</a>，则组件将异步加载和编译。</font></p>
<p><font style="vertical-align: inherit;">确保提供的 URL 完整且正确，特别是从本地文件系统加载文件时使用</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtcore/qurl.html#fromLocalFile"><font style="vertical-align: inherit;">QUrl::fromLocalFile</font></a><font style="vertical-align: inherit;"> ()。</font></p>
<p><font style="vertical-align: inherit;">相对路径将针对</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlengine.html#baseUrl"><font style="vertical-align: inherit;">QQmlEngine::baseUrl()</font></a><font style="vertical-align: inherit;">解析，除非指定，否则它是当前工作目录。</font></p>
<!-- @@@loadUrl -->
<!-- $$$progressChanged -->
<h3 class="fn" id="progressChanged"><a name="progressChanged"></a><code>[signal] </code><span class="type">void</span> QQmlComponent::<span class="name">progressChanged</span>(<span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> <i>progress</i>)</h3>
<p><font style="vertical-align: inherit;">每当组件的加载进度发生变化时发出。</font><i><font style="vertical-align: inherit;">进度</font></i><font style="vertical-align: inherit;">将是 0.0（未加载）和 1.0（已完成）之间的当前进度。</font></p>
<p><b>注意：</b> <span lang="zh-cn">属性</span><a href="qqmlcomponent.html#progress-prop">progress</a><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#progress-prop"><font style="vertical-align: inherit;">的</font></a><font style="vertical-align: inherit;">通知信号。</font></p><!-- @@@progressChanged -->
<!-- $$$setData[overload1]$$$setDataconstQByteArray&constQUrl& -->
<h3 class="fn" id="setData"><a name="setData"></a><code>[slot] </code><span class="type">void</span> QQmlComponent::<span class="name">setData</span>(const <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> &amp;<i>data</i>, const <span class="type"><a href="../qtcore/qurl.html">QUrl</a></span> &amp;<i>url</i>)</h3>
<p><font style="vertical-align: inherit;">设置</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html"><font style="vertical-align: inherit;">QQmlComponent</font></a><font style="vertical-align: inherit;">以使用给定的 QML</font><span lang="zh-cn">
</span><i><font style="vertical-align: inherit;">data</font></i><font style="vertical-align: inherit;">。如果提供了</font><i><font style="vertical-align: inherit;">url</font></i><font style="vertical-align: inherit;">，则它用于设置组件名称并为此组件解析的项目提供基本路径。</font></p>
<!-- @@@setData -->
<!-- $$$statusChanged -->
<h3 class="fn" id="statusChanged"><a name="statusChanged"></a><code>[signal] </code><span class="type">void</span> QQmlComponent::<span class="name">statusChanged</span>(<span class="type"><a href="qqmlcomponent.html#Status-enum">QQmlComponent::Status</a></span> <i>status</i>)</h3>
<p><font style="vertical-align: inherit;">每当组件的状态发生变化时发出。</font><i><font style="vertical-align: inherit;">status</font></i><font style="vertical-align: inherit;">将成为新的状态。</font></p>
<p><b>注意：</b> <font style="vertical-align: inherit;">属性</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtqml/qqmlcomponent.html#status-prop"><font style="vertical-align: inherit;">状态的</font></a><font style="vertical-align: inherit;">通知信号。</font></p><!-- @@@statusChanged -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
